﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using MoneyWentWhere.DataModel;
using MoneyWentWhere.DataModel.Binding;
using MoneyWentWhere.WinFormsUI.Reports;
using BrightIdeasSoftware;

namespace MoneyWentWhere.WinFormsUI
{
    public partial class ReportPanel : UserControl
    {
        ObjectListView _view;
        
        MoneyDataSet _dataSet;
        ReportType _reportType;

        public ReportPanel()
        {
            InitializeComponent();
        }

        public ReportType ReportType
        {
            get { return _reportType; }
            set
            {
                _reportType = value;

                if (_view != null)
                {
                    Controls.Remove(_view);
                    _view.Dispose();
                    _view = null;
                }

                _view = null;
                if (_reportType != null)
                {
                    _view = _reportType.CreateView();
                    _view.Dock = DockStyle.Fill;
                    Controls.Add(_view);

                    if (_dataSet != null)
                    {
                        _reportType.FillView(_dataSet);
                    }
                }
            }
        }

        public MoneyDataSet DataSet
        {
            get { return _dataSet; }
            set
            {
                _dataSet = value;
                if (value == null) { return; }
                
                if (_reportType != null)
                {
                    _reportType.FillView(_dataSet);
                }
            }
        }


    }

}
